define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/order/index',
                    add_url: 'user/order/add',
                    edit_url: 'user/order/edit',
                    del_url: 'user/order/del',
                    multi_url: 'user/order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'buyer_id', title: __('Buyer_id')},
                        {field: 'seller_id', title: __('Seller_id')},
                        {field: 'market_price', title: __('Market_price'), operate:'BETWEEN'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
                        {field: 'real_name', title: __('Real_name')},
                        {field: 'alipay_account', title: __('alipay_account')},
                        {field: 'alipay_pic', title: __('alipay_pic'), formatter: Table.api.formatter.image},
                        {field: 'wechat_account', title: __('wechat_account')},
                        {field: 'wechat_pic', title: __('wechat_pic'), formatter: Table.api.formatter.image},
                        // {field: 'bank_name', title: __('Bank_name')},
                        // {field: 'branch_bank_name', title: __('Branch_bank_name')},
                        // {field: 'bank_card', title: __('Bank_card')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'matchtime', title: __('Matchtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'finishtime', title: __('Finishtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), visible:false, searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5')}},
                        {field: 'status_text', title: __('Status'), operate:false, formatter: function (value, row, index) {
                            if (value=='未收到款') {
                                return '<font color="red">'+value+'</font>'
                            }else{
                                return value;
                            }
                        }},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }

    };
    return Controller;
});